﻿<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@page import="global.Constants"%>
    <%@page import="util.ServletHelp"%>
    <%@page import="com.aiflow.Action.DepartmentAction"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
	<script type="text/javascript">
	    //这里的全局是为了修改之后的刷新
	    var superviseStreamListGrid;
	    var superviseStreamListStore;
		$(document).ready(function(){
			 // 全局参数
			var baseParams = {limit:<%=Constants.PAGE_SIZE %>,start : 0};
			var EXT_QUERY_TIME_OUT = 1200000;

			// 传报数据源  userName,u.telep ,d.name as targetName
		    superviseStreamListStore = new Ext.data.JsonStore({
		        url: '${pageContext.request.contextPath}/findSuperviseStream.action',
		        root: 'datas',
				timeout : EXT_QUERY_TIME_OUT,
		        totalProperty: 'results',
		        fields: ['id','superviseId','MVB_CALLER','userName','tel','name','sendTime','calltime','answertime','endtime','duration','supervise_status','region_name' ],
		        baseParams: baseParams,
		        autoLoad: true,
				listeners : {  
          load : function() {  
              isDetailReady = true;// 查询置换标志为已查过   
            }  
            }  
		    });
		    
		    //工单类型
	        var superviseType = new Ext.data.ArrayStore({  
                    fields : ['superviseType', 'superviseTypeName'],  
		            data : <%=ServletHelp.getArrayFromMap(Constants.Supervise_TYPE_MAP, null)%>,
		            sortInfo: {field: "superviseType", direction: "ASC"}
	        });
			
			var supervisetypeQueryCombo = new Ext.form.ComboBox({
				id :'supervisetypeQueryCombo', 
				triggerAction: 'all', 
				typeAhead: true, 
				store: superviseType, 
				mode : 'local',
				valueField: 'superviseType', 
				displayField: 'superviseTypeName', 
				editable: true, 
				width:100,
				lazyRender: true,
				allowBlank:true
			});
			
			// 区域  数据源  getDepartmentCombo
	        var regionStore = new Ext.data.ArrayStore({  
	            fields : ['region_id', 'region_name'],  
	            data : <%=DepartmentAction.getDepartmentNameCombo("1")%>,
	            sortInfo: {field: "region_id", direction: "ASC"}
	        });
		 
		   // 工具栏
		   var superviseStreamListToolbar = new Ext.Toolbar({
		    	renderTo: 'superviseStreamListToolbarDiv',
		    	items: [
					
		             new Ext.Button({
					    id: 'superviseStream-down-button',
					    text: '导出',
						iconCls: 'page_white_excel'
						
					}),
					'-','查询： 日期',' 起',
					{  
			               xtype:'datefield',
			                id:'startsuperviseTime',
			                hiddenName: 'startTime',
			                fieldLabel: '开始',
                            format:'Y-m-d',
			                mode : 'local',
			                triggerAction: "all",
			                allowBlank:true,
			                editable: false,
			                width: 130,
							vtype : 'daterange',
			                anchor:'98%',
							endDateField : 'endsuperviseTime'
			           },' 止 ',
			           {  
			                xtype:'datefield',
			                id:'endsuperviseTime',
			                hiddenName: 'endTime',
			                fieldLabel: '开始',
                            format:'Y-m-d',
			                mode : 'local',
			                triggerAction: "all",
			                allowBlank:true,
			                editable: false,
							vtype : 'daterange',
			                width: 130,
			                anchor:'98%',
							startDateField : 'startsuperviseTime'
			           },'  电话号码',
			           {// 账号
			                id:'tele',
			                xtype:'textfield',
			                name: 'tele',
			                fieldLabel: '手机',
			                anchor:'98%',
			                allowBlank:false,
			                maxLength: 20
			           },'-',
			           '地市',
			           {  
			                xtype:'combo',
			                id:'region',
			                hiddenName: 'region',
			                fieldLabel: '省市',
			                store: regionStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'region_id',
			                displayField: 'region_name',
			                allowBlank:true,
			                editable: false,
			                width: 100,
			                anchor:'98%'
			           },
		             new Ext.Button({
					    id: 'superviseStream-query-button',
					    text: '查询',
						iconCls: 'magnifier'
						
					})
				]
			});
 
			// 数据表格    dept_name spec
			var sm = new Ext.grid.CheckboxSelectionModel();
			superviseStreamListGrid = new Ext.grid.EditorGridPanel({
				id: 'superviseStreamListGrid',
				renderTo: 'superviseStreamListGridDiv',
				border: false,
				stateful: true,
			    autoScroll: 'auto',
		        store: superviseStreamListStore,
		        loadMask: true,
		        cm: new Ext.grid.ColumnModel({
		            defaults: {
		                width: 100,
		                sortable: true
		            },
			        columns: [   //id,Alarm_id,Region_name,Alarm_pro,Dn,Dn_type,Alarm_time,Org_severity
						sm,
						new Ext.grid.RowNumberer({header:'№',width:20}),
                        {id:'superviseId',header: '工单号', width: 140,hidden: false, sortable: true, dataIndex: 'superviseId'},
                        {id:'region_name',header: '地市', width: 70,hidden: false, sortable: true, dataIndex: 'region_name'},
			            {id:'MVB_CALLER',header: 'MVB_CALLER', width: 130,hidden: false, sortable: true, dataIndex: 'MVB_CALLER'},
			            {id:'userName',header: '姓名', width: 180,hidden: false, sortable: true, dataIndex: 'userName'},
			            {id:'tel',header: '电话', width: 100,hidden: false, sortable: true, dataIndex: 'tel'},
			            {id:'name',header: '督办对象', width: 120,hidden: false, sortable: true, dataIndex: 'name'},
                        {id:'sendTime',header: '派单时间', width: 120,hidden: false, sortable: true, dataIndex: 'sendTime'},
			            {id:'calltime',header: '呼叫时间', width:120,hidden: false, sortable: true, dataIndex: 'calltime'},
			            {id:'answertime',header: '应答时间', width:120,hidden: false, sortable: true, dataIndex: 'answertime'},
                        {id:'endtime',header: '结束时间', width:120,hidden: false, sortable: true, dataIndex: 'endtime'},
                        {id:'duration',header: '通话时长(秒)', width:120,hidden: false, sortable: true, dataIndex: 'duration'},
                        {id:'supervise_status',header: '督办类型', width:80,hidden: false, sortable: true, dataIndex: 'supervise_status',renderer: function(value, cellmeta,record){return typeComboRenderer(value, cellmeta,record);}}
                        ]
		        }),
		        sm: sm,
		        columnLines: true,
		         bbar: new Ext.PagingToolbar({
					pageSize: <%=Constants.PAGE_SIZE %>,
					store: superviseStreamListStore,
					displayInfo: true,
					displayMsg: Anynote.PAGINGTOOLBAR_DISPLAYMSG,
					emptyMsg: Anynote.PAGINGTOOLBAR_EMPTYMSG,
					doLoad: function(start){
						baseParams.start = start;
						var startTime = Ext.getCmp("startsuperviseTime").getValue();
			            var endTime = Ext.getCmp("endsuperviseTime").getValue();
			            var backComm = Ext.getCmp("tele").getValue(); 
				        baseParams.startTime = startTime;
				        baseParams.endTime = endTime;
				        baseParams.tele = backComm;
						this.store.load({params: baseParams});
					}
		        })
		    });
		    
			// 设置Grid高度和宽度
		    Anynote.resizeGridTo("superviseStreamListGrid", 0, 56);
		    
		    // 类型ComboBox设值  
			function typeComboRenderer(value, cellmeta,record){
				var index = superviseType.find(Ext.getCmp('supervisetypeQueryCombo').valueField,value);
				var record = superviseType.getAt(index);
				var displayText = "";
				if(record==null){
					displayText = value;
				}else{
					displayText = record.data.superviseTypeName;
				}
				return displayText;
			}
		})  
			
			 $("#superviseStream-query-button").click(function(){
			   var reg = Ext.getCmp("region").getValue();
			   var startTime = Ext.getCmp("startsuperviseTime").getValue();
			   var endTime = Ext.getCmp("endsuperviseTime").getValue();
			   var backComm = Ext.getCmp("tele").getValue(); 
			   var basePar  = {limit:<%=Constants.PAGE_SIZE %>,start : 0};
			   basePar.startTime = startTime;
			   basePar.endTime = endTime;
			   basePar.tele = backComm;
			   basePar.region = reg;
			   superviseStreamListStore.reload({params:basePar});
			 })
					     
				  $("#superviseStream-down-button").click(function(){   //   下载 
					 var reg = Ext.getCmp("region").getValue();
					 var startTime = Ext.getCmp("startsuperviseTime").getValue();
				     var endTime = Ext.getCmp("endsuperviseTime").getValue();
				     var backCom = Ext.getCmp("tele").getValue();
				     if(startTime != ''){
				     startTime = Ext.util.Format.date(startTime, 'Y-m-d');
				     }
				     if(endTime != ''){
				     endTime = Ext.util.Format.date(endTime, 'Y-m-d');
				     }
			         window.location.href = "${pageContext.request.contextPath}/callStream_Supervisedown.action?startTime="+startTime+"&endTime="+endTime+"&tele="+backCom+"&region="+reg;
				  })
	</script>
</head>
<body>
<div id="superviseStreamListDiv">
	<div id="superviseStreamListToolbarDiv"></div>
	<div id="superviseStreamListGridDiv" style="width:100%;height:100%;"></div>
</div>
</body>
</html>